/********************************************************************************
* File Name:	mainwindow.cpp
* Description:	第3章 实例13：MdiArea的实例
* Reference book:《Linux环境下Qt4图形界面与MySQL编程》，机械工业出版社.2012.1
* E_mail: openlinux2011@gmail.com
*
********************************************************************************/
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QTextEdit>

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    QTextEdit *windows1 = new QTextEdit;
    windows1->setHtml("C");
    ui->mdiArea->addSubWindow(windows1);

    QTextEdit *windows2 = new QTextEdit;
    windows2->setHtml("C++");
    ui->mdiArea->addSubWindow(windows2);

    QTextEdit *windows3 = new QTextEdit;
    windows3->setHtml("Java");
    ui->mdiArea->addSubWindow(windows3);

    QTextEdit *newWindows = new QTextEdit;
    newWindows->setHtml("New Windows!");
    ui->mdiArea->addSubWindow(newWindows);

    ui->mdiArea->cascadeSubWindows();
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::on_btnPrevious_clicked()
{
    ui->mdiArea->activatePreviousSubWindow();
}

void MainWindow::on_btnNext_clicked()
{
    ui->mdiArea->activateNextSubWindow();
}

void MainWindow::on_btnClose_clicked()
{
    ui->mdiArea->closeActiveSubWindow();
}

//void MainWindow::on_btnAdd_clicked()
//{
//    QTextEdit *newWindows = new QTextEdit;
//    newWindows->setHtml("New Windows!");
//    ui->mdiArea->addSubWindow(newWindows);
//}

void MainWindow::on_btnCloseAll_clicked()
{
    ui->mdiArea->closeAllSubWindows();
}
